package com.leyou.search.config;

import com.leyou.search.interceptor.AppTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器
 */
@Component
public class MvcConfig implements WebMvcConfigurer{
    @Autowired(required = false)
    private AppTokenInterceptor appTokenInterceptor;

    //往Mvc环境添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //addInterceptor:添加拦截器对象
        /**
         * 拦截规则问题：
         *   1）默认情况下，会拦截所有请求 (  .addPathPatterns("/**") )
         *   2) 如果希望排除一些路径，可以使用excludePathPatterns()方法
         */
        registry.addInterceptor(appTokenInterceptor);
    }
}
